package com.yanqu.road.server.cmd.activity.twins;

import com.yanqu.road.entity.activity.twins.config.TwinsConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TwinsProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.twins.TwinsModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.twins.TwinsMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_TWINS_PVE_AUTO_BATTLE, desc = "")
public class TwinsPveAutoBattleCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        TwinsConfig config = TwinsMgr.getConfig();
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_TWINS_ACTIVITY_NOT_IN_TIME;
            return;
        }
        int checkGroup = player.getModule(TwinsModule.class).checkGroup();
        if (checkGroup != 0) {
            ret = checkGroup;
            return;
        }

        player.getModule(TwinsModule.class).autoPveGameBattle();
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
        TwinsProto.TwinsPveGameAutoBattleRespMsg.Builder respMsg = TwinsProto.TwinsPveGameAutoBattleRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_TWINS_PVE_AUTO_BATTLE, respMsg);
    }
}
